package com.villaday.idf.adapter2;

import android.content.Context;
import android.graphics.Paint;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model2.Presell_list;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;

import byc.imagewatcher.MessagePicturesLayout;

/**
 * 首页动态列表
 */

public class HomeTeMaiAdapter extends AbsRecyclerViewAdapter<Presell_list.BodyBean.ListBean> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private MessagePicturesLayout.Callback mCallback;
    private String roleType;

    public HomeTeMaiAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_home2v_type2, /*R.layout.item_dynamic_1, R.layout.item_dynamic_2,*/ R.layout.item_page_loading,
                R.layout.item_page_bottom, R.layout.item_home2v_type2_top);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;

        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();


    }

    public void setRoleType() {
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();
    }

    @Override
    public int getItemType(Presell_list.BodyBean.ListBean d) {
        return d.getMyType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, Presell_list.BodyBean.ListBean d, int position) {
        switch (d.getMyType()) {

            case 0:
            case 3: {
                holder.bindSimpleDraweeView(R.id.sdv, d.getImageUrl())
                        .bindTextViewWithHtml(R.id.tv_priceFuHao, "&yen;")

                        .bindTextView(R.id.tv_title, d.getName())
                        .bindTextView(R.id.tv_price, d.getCurrentPrice())
                        .bindTextViewWithHtml(R.id.tv_yuanjia, "&yen;" + (d.getOriginalPrice()))
                        .bindTextView(R.id.tv_zhe, d.getDiscountRate() + "折")
                        .bindTextViewWithHtml(R.id.tv_zhuanNum, "加返" + "&yen;" + (d.getExtraRebateAmount()))
                        .bindTextViewWithHtml(R.id.tv_Zhuan, "立返" + "&yen;" + (d.getRebateAmount()))
                        .bindTextView(R.id.date, d.getSaleTips())
                        .bindTextView(R.id.tv_chaodi, (d.getTags()==null||d.getTags().size()==0||TextUtils.isEmpty(d.getTags().get(0)))?"":d.getTags().get(0))
                        .setViewVisible(R.id.tv_chaodi, (d.getTags()==null||d.getTags().size()==0||TextUtils.isEmpty(d.getTags().get(0)))?View.GONE:View.VISIBLE)

                        .setViewVisible(R.id.tv_zhuanNum, "0".equals(roleType) ? View.GONE : d.getExtraRebateAmount() == null || "0".equals(d.getExtraRebateAmount()) ? View.GONE : View.VISIBLE)
                        .setViewVisible(R.id.ll_Zhuan, "0".equals(roleType) ? View.GONE : d.getRebateAmount() == null || "0".equals(d.getRebateAmount()) ? View.GONE : View.VISIBLE)

                        .setViewVisible(R.id.img_zhuanfa, "0".equals(roleType) ? View.INVISIBLE : View.VISIBLE);


                ImageView imgZhuanfa = (ImageView) holder.getView(R.id.img_zhuanfa);
                imgZhuanfa.setOnClickListener(onClickListener);
                imgZhuanfa.setTag(position);
                TextView view = (TextView) holder.getView(R.id.tv_yuanjia);
//添加删除线
                view.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);


                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_chaodi), false);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_priceFuHao), true);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_price), true);
                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_yuanjia), false);

                PhoneUtil.setExternalFont(context, (TextView) holder.getView(R.id.tv_Zhuan), false);


                break;
            }
            case 1: {
                onAdapterCallbackListener.onCallback();
            }
            break;


        }


    }
}
